package aod.android.com.bernay.util;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * <p>文件描述： <p>
 * <p>作者：${SYC}<p>
 * <p>创建时间：2019/4/10<p>
 */
public class SharePreUtils {
    private volatile static SharePreUtils utils;
    private SharedPreferences sharePre = null;
    private SharedPreferences shareFrist = null;
    private SharedPreferences.Editor mEditor;
    Context context;
    //    //当前登录用户
//    private static  UserBean.DataBean sUser;
    private static final String SPF_FILE_USER_NAME = "spf_quark_user";

    public SharePreUtils(Context context) {
        if (context != null) {
            sharePre = context.getSharedPreferences("first_language", Context.MODE_PRIVATE);
            shareFrist = context.getSharedPreferences("first_pref", Context.MODE_PRIVATE);
        }
    }

    /**
     * 第一次创建实例的时候会同步所有线程，以后有线程再想获取SharePreUtils的实例就不需要进行同步，直接返回实例即可。
     *
     * @param context
     * @return
     */
    public static SharePreUtils newInstance(Context context) {
        if (utils == null) {
            synchronized (SharePreUtils.class) {
                if (utils == null) {
                    utils = new SharePreUtils(context);
                }
            }
        }
        return utils;
    }

    /**
     * 存入绑定设备标识
     *
     * @param riskLevel
     */


    public void updateFixing(int riskLevel) {
        if (sharePre != null) {
            mEditor = sharePre.edit();
            mEditor.putInt("bindfixing", riskLevel).commit();
        }
    }

    /**
     * 获取绑定设备标识
     */
    public int getFixing() {
        if (sharePre != null) {
            if (sharePre.getInt("bindfixing", -1) != -1) {
                return sharePre.getInt("bindfixing", -1);
            }
        }
        return 0;
    }

    /**
     * @param userid 存入userid
     */
    public void updata(String userid) {
        if (sharePre != null) {
            mEditor = sharePre.edit();
            mEditor.putString("userid", userid).commit();
        }
    }

    /**
     * 取出userid
     */
    public String getUserId() {
        if (sharePre != null) {
            return sharePre.getString("userid", "");
        }
        return "";
    }

    /**
     * @param Token 存入
     */
    public void updataToken(String Token) {
        if (sharePre != null) {
            mEditor = sharePre.edit();
            mEditor.putString("Token", Token).commit();
        }
    }

    /**
     * 取出userid
     */
    public String getToken() {
        if (sharePre != null) {
            return sharePre.getString("Token", "");
        }
        return "";
    }


}
